package com.shd.edanpei.ui.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

import com.shd.edanpei.R;
import com.shd.edanpei.ui.adapter.PlanLineAdapter;
import com.shd.edanpei.bean.PlanLineBean;
import com.shd.edanpei.enums.StatusEnum;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mc on 2018/9/21.
 * 订单进度
 */

public class PlanLineView extends LinearLayout {

    private RecyclerView recyclerView;
    private PlanLineAdapter mAdapter;

    public PlanLineView(Context context) {
        super(context);
        initView();
    }

    public PlanLineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    public PlanLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView();
    }

    private void initView() {
        LayoutInflater.from(getContext()).inflate(R.layout.plan_line_view, this);
        recyclerView = findViewById(R.id.recycler_view);

        mAdapter = new PlanLineAdapter(getContext());
        //设置横向RecyclerView
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(mAdapter);

    }

    public void setData(int status) {
        List<PlanLineBean> list = new ArrayList<>();

        if (status == StatusEnum.unpaid.getStatus()) {
            //未支付

        } else if (status == StatusEnum.applying.getStatus()) {
            //已支付，未被接单

        } else if (status == StatusEnum.first.getStatus()) {
            //已被接单，未初审
            list.add(new PlanLineBean("接单", true));
            list.add(new PlanLineBean("初审", false));
            list.add(new PlanLineBean("终审", false));
            list.add(new PlanLineBean("成功", false));

        } else if (status == StatusEnum.last.getStatus()) {
            //已初审，未终审核
            list.add(new PlanLineBean("接单", true));
            list.add(new PlanLineBean("初审", true));
            list.add(new PlanLineBean("终审", false));
            list.add(new PlanLineBean("成功", false));
        } else if (status == StatusEnum.waitService.getStatus()) {
            //已终审，未支付服务费
            list.add(new PlanLineBean("接单", true));
            list.add(new PlanLineBean("初审", true));
            list.add(new PlanLineBean("终审", true));
            list.add(new PlanLineBean("成功", false));
        } else if (status == StatusEnum.waitLoan.getStatus()) {
            //未放款
            list.add(new PlanLineBean("接单", true));
            list.add(new PlanLineBean("初审", true));
            list.add(new PlanLineBean("终审", true));
            list.add(new PlanLineBean("成功", false));
        } else if (status == StatusEnum.waitfirm.getStatus()) {
            //已放款
            list.add(new PlanLineBean("接单", true));
            list.add(new PlanLineBean("初审", true));
            list.add(new PlanLineBean("终审", true));
            list.add(new PlanLineBean("成功", false));
        } else if (status == StatusEnum.success.getStatus()) {
            //交易成功
            list.add(new PlanLineBean("接单", true));
            list.add(new PlanLineBean("初审", true));
            list.add(new PlanLineBean("终审", true));
            list.add(new PlanLineBean("成功", true));
        } else if (status == StatusEnum.error.getStatus()) {
            //订单超时，无人接单

        } else if (status == StatusEnum.cancel.getStatus()) {
            //未支付，撤销订单

        } else if (status == StatusEnum.refuse.getStatus()) {
            //被拒绝

        } else if (status == StatusEnum.waitRepay.getStatus()) {
            //已支付，撤销订单,退款中
            list.add(new PlanLineBean("发起退单", true));
            list.add(new PlanLineBean("系统受理", true));
            list.add(new PlanLineBean("成功", false));
        } else if (status == StatusEnum.repaySuccess.getStatus()) {
            //退款成功
            list.add(new PlanLineBean("发起退单", true));
            list.add(new PlanLineBean("系统受理", true));
            list.add(new PlanLineBean("成功", true));
        } else if (status == 100) {
            //支付服务费
            list.add(new PlanLineBean("核对信息", true));
            list.add(new PlanLineBean("线下转账", false));
            list.add(new PlanLineBean("系统受理", false));
            list.add(new PlanLineBean("审核通过", false));
        } else if (status == 101) {
            list.add(new PlanLineBean("核对信息", true));
            list.add(new PlanLineBean("线下转账", true));
            list.add(new PlanLineBean("系统受理", false));
            list.add(new PlanLineBean("审核通过", false));
        } else if (status == 102) {
            list.add(new PlanLineBean("核对信息", true));
            list.add(new PlanLineBean("线下转账", true));
            list.add(new PlanLineBean("系统受理", true));
            list.add(new PlanLineBean("审核通过", false));
        } else if (status == 103) {
            list.add(new PlanLineBean("核对信息", true));
            list.add(new PlanLineBean("线下转账", true));
            list.add(new PlanLineBean("系统受理", true));
            list.add(new PlanLineBean("审核通过", true));
        }

        mAdapter.setNewData(list);

    }

}
